package com.bjsxt.func;

import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiConsumer;

public class TestFuntionInterface2 {
    public static void main(String[] args) {

        Map<String,String> map = new TreeMap<String,String>();
        //使用Map对象存储键值对
        map.put("cn","China");
        map.put("jp","Japan");
        map.put("us","the United States");
        map.put("us","America");
        map.put("uk","the United Kingdom");
        map.put("en","the Untied Kingdom");

        //方式1：匿名内部类
        BiConsumer<String,String> biConsumer = new BiConsumer<String, String>() {
            @Override
            public void accept(String key, String value) {
                System.out.println(key+"======>"+value);
            }
        };

        map.forEach(biConsumer);

        //方式2：Lambda表达式
        map.forEach((k,v)->{System.out.println(k+"----->"+v);});
    }
}
